package jd.se.returnrequest;

import com.github.pagehelper.ISelect;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface ReturnRequestDao {
    @Insert("insert into return_request(from_id, to_id, b_id, time) values(#{from_id},#{to_id},#{b_id},#{time})")
    void insertReturnRequest(ReturnRequest request);

    @Delete("delete from borrow where u_id = #{u_id} and b_id = #{b_id}")
    void deleteBorrowInfo(BInfo bInfo);

    @Delete("delete from return_request where from_id = #{u_id} and to_id = #{to_id} and b_id = #{b_id}")
    void deleteReturnRequest(BInfo bInfo);

    @Select("select time from return_request where from_id = #{u_id} and to_id = #{to_id} and b_id = #{b_id}")
    Timestamp getRequestTime(BInfo bInfo);

    @Select("select return_date from borrow where u_id = #{u_id} and b_id = #{b_id}")
    Date getReturnDate(BInfo bInfo);

    List<ReturnRequestShow> showRequests(String to_id);

    @Update("update user set credit=credit-5 where u_id = #{u_id}")
    void deductCredit(BInfo info);
}
